package hotel.callback.oversea.controller;

import hotel.callback.oversea.service.SwitchPushRoomService;
import hotel.base.oversea.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;


/**
 * 创建售卖房型控制
 * @Author lmf
 * @Date 2020/6/10 13:39
 **/
@Slf4j
@RestController
@RequestMapping("/switchCreateRoomCallback")
@Api(value = "SwitchCreateRoomCallbackController",tags = {"创建售卖房型"})
public class SwitchCreateRoomCallbackController {
    @Autowired
    SwitchPushRoomService switchPushRoomService;
    /**
     * @author: lmf
     * @date: 2020/8/6 18:26
     * 美团价格 库存 房态 异步通知,根据美团价格房态库存通知推送给携程  ---》》携程接口有请求次数限制  不可美团异步直接调，需要缓存队列再定时器处理
     * 2021-04-20 新增改造方法为构造数据
     */
    @RequestMapping("/notityModifyRoomInfoByManyThreadCallback")
    @ApiOperation(value = "根据美团价格房态库存通知推送给携程",notes = "必须经过oauth授权")
    public Result<Object> notityModifyRoomInfoByManyThread(){
        ExecutorService executorService = Executors.newFixedThreadPool(1);
        executorService.submit(() -> {
            switchPushRoomService.manyThreadPushRoomData();
        });
        executorService.shutdown();
        return new Result<>();
    }

    /***
    * @Author: lmf
    * @Date: 2021/4/20
     * 推送给携程
    */
    @RequestMapping("/pushRoomToSwitch")
    @ApiOperation(value = "根据美团价格房态库存通知推送给携程",notes = "必须经过oauth授权")
    public Result<Object> pushRoomToSwitch(){
        return switchPushRoomService.pushRoomToSwitch();
    }

    /***
     * @Author: lmf
     * @Date: 2021/4/20
     * 封装推送给携程的数据
     */
    @RequestMapping("/makePushRoomData")
    @ApiOperation(value = "根据美团价格房态库存通知推送给携程",notes = "必须经过oauth授权")
    public Result<Object> makePushRoomData(){
        return switchPushRoomService.makePushRoomData();
    }

    /***
    * @Author: lmf
    * @Date: 2021/1/7
     * 测试
    */
    @RequestMapping("/test")
    public Result<Object> test(){
        log.info("========测试============");
        switchPushRoomService.manyThreadPushRoomDataByTest();
        return new Result<>();
    }

    /**
     * @author: lmf
     * @date: 2020/8/6 18:26
     * 美团价格 库存 房态 异步通知,根据爬虫爬取美团价格房态库存通知推送给携程  ---》》携程接口有请求次数限制  不可美团异步直接调，需要缓存队列再定时器处理
     */
    @RequestMapping("/notityModifyRoomInfoByManyThreadCallbackBySplider")
    @ApiOperation(value = "根据美团价格房态库存通知推送给携程",notes = "必须经过oauth授权")
    public Result<Object> notityModifyRoomInfoByManyThreadCallbackBySplider(){
        return switchPushRoomService.notityModifyRoomInfoByManyThreadCallbackBySplider();
    }

}
